<template>
  <div class="view">
    <OperateC
        :top-level="topLevel"
        :add="addSysOrg"
        :edit="editSysOrg"
        :remove="removeSysOrg"
        :add-show="this.$getButtonAuth('org:add')"
        :remove-show="this.$getButtonAuth('org:del:batch')"
    />
    <SysOrgTable
        :top-level="topLevel"
        :add-child-show="this.$getButtonAuth('org:add:child')"
        :edit-show="this.$getButtonAuth('org:edit')"
        :del-show="this.$getButtonAuth('org:del')"
    />
    <SysOrgDialog></SysOrgDialog>
  </div>
</template>

<script>
  import SysOrgDialog from "@/components/dialog/SysOrgDialog";
  import OperateC from "@/components/OperateC";
  import SysOrgTable from "@/components/table/SysOrgTable";
  import {deleteSysOrgByIds, getSysOrgs} from "@/api/sysOrg";
  export default {
    name: "SysOrgView",
    components: {SysOrgDialog, OperateC, SysOrgTable},
    data() {
      return {
        topLevel: -1
      }
    },
    methods: {
      addSysOrg() {
        let params = {
          dialogFormVisible: true,
          dialogTitle: "添加"
        }
        this.$store.commit("org/openDialogForm", params);
      },
      editSysOrg() {
        let selected = this.$store.state.org.multipleSelection;
        if (selected.length < 1) {
          this.$message.warning("你还没有选中数据哦！");
          return;
        }
        if (selected.length > 1) {
          this.$message.warning("一次只能修改一条数据哦！")
          return;
        }
        this.$store.dispatch("sysOrg/editSysOrg", selected[0]);
      },
      removeSysOrg() {
        let selected = this.$store.state.org.multipleSelection;
        if (selected.length < 1) {
          this.$message.warning("请先选择要删除的数据哦！");
          return;
        }
        this.$confirm('确定删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteSysOrgByIds(selected).then((res) => {
            this.$message.success(res.data.msg);
            // 刷新
            let params = {
              "current": this.$store.state.org.currentPage,
              "size": this.$store.state.org.pageSize
            };
            getSysOrgs(params).then((res) => {
              this.$store.state.org.tableData = res.data.data;
              this.$store.state.org.total = res.data.total;
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
    }
  }
</script>

<style scoped>

</style>
